package cn.com.scitc.licenseplateback.dao;

import cn.com.scitc.licenseplateback.model.JUserTokensEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.transaction.annotation.Transactional;

public interface JUserTokenDao extends CrudRepository<JUserTokensEntity,Integer> {

    /**
     * 根据编码后的 userId 进行用户自动登录的信息查询
     * @param userId
     * @return
     */
    @Query(value = "select j from JUserTokensEntity j where j.userId = :userId")
    JUserTokensEntity findByUserId(String userId);


    /**
     * 根据编码后的用户 userId 删除用户的自动登录信息
     * @param userId
     * @return
     */
    @Modifying
    @Transactional
    @Query(value = "delete from j_user_tokens where user_id = :userId", nativeQuery = true)
    int deleteByUserId(String userId);
}
